package ipower.studentworks.action;

import java.util.ArrayList;
import java.util.List;

import ipower.pageModel.TreeNode;
import ipower.studentworks.domain.UnitBase;
import ipower.studentworks.pageModel.UnitInfo;
import ipower.studentworks.service.UnitService;

/**
 * 学校单位。
 * @author young。
 * @since 2013-11-06。
 * */
public class UnitAction extends BaseDataAction<UnitInfo> {
	private UnitInfo info = new UnitInfo();
	@Override
	public UnitInfo getModel() {
		return this.info;
	}

	@Override
	protected String deletePrimaryString() {
		return this.getModel().getId();
	}
	
	public void combobox(){
		List<TreeNode> results = new ArrayList<>();
		List<UnitBase> list = ((UnitService)this.service).loadAllUnits(this.getModel().getName());
		if(list != null && list.size() > 0){
			for(UnitBase u : list){
				TreeNode tn = new TreeNode();
				tn.setId(u.getId());
				tn.setText(u.getName());
				results.add(tn);
			}
		}
		this.writeJson(results);
	}
}